<?php

namespace App\Http\Controllers\Api\V1;
use App\Models\Account;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Api\V1\Resources\AccountResource;
use OpenAI;


class GptController extends Controller
{
	public function index()
	{

		 $yourApiKey = getenv('DASHSCOPE_API_KEY');
		
		 $client = OpenAI::factory()
				    ->withApiKey($yourApiKey)
				    ->withBaseUri('https://dashscope.aliyuncs.com/compatible-mode/v1') // default: api.openai.com/v1
				    ->withHttpClient($client = new \GuzzleHttp\Client([])) // default: HTTP client found using PSR-18 HTTP Client Discovery
				    ->withHttpHeader('X-My-Header', 'foo')
				    ->withQueryParam('my-param', 'bar')
				    ->withStreamHandler(fn (RequestInterface $request): ResponseInterface => $client->send($request, [
				        'stream' => true // Allows to provide a custom stream handler for the http client.
				    ]))
			    ->make();
		/*$params = [
			'api_key'=>$yourApiKey, # 如果您没有配置环境变量，请在此处用您的API Key进行替换
    	    'base_url'=>"https://dashscope.aliyuncs.com/compatible-mode/v1",  # 填写DashScope服务的base_url
		];
		$client = OpenAI::client($params);*/
	
		$result = $client->chat()->create([
		    'model' => 'qwen-turbo',
		    'messages' => [
		    	['role' => 'user', "content"=> "你是谁"],
		       
		    ],
		]);
		//dd($result);
		echo $result->choices[0]->message->content; 
	}


}
